package com.ruoyi.eamp.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.eamp.domain.EampEquipment;
import com.ruoyi.eamp.domain.EampEquipmentUse;
import com.ruoyi.eamp.domain.vo.EampEquipmentMyAndEquip;
import com.ruoyi.eamp.mapper.EampEquipmentMapper;
import com.ruoyi.eamp.mapper.EampEquipmentUseMapper;
import org.apache.poi.ss.formula.functions.Now;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.eamp.mapper.EampEquipmentMyMapper;
import com.ruoyi.eamp.domain.EampEquipmentMy;
import com.ruoyi.eamp.service.IEampEquipmentMyService;

/**
 * 我的仪器使用Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-08
 */
@Service
public class EampEquipmentMyServiceImpl implements IEampEquipmentMyService 
{
    @Autowired
    private EampEquipmentMyMapper eampEquipmentMyMapper;
    @Autowired
    private EampEquipmentMapper eampEquipmentMapper;
    @Autowired
    private EampEquipmentUseMapper eampEquipmentUseMapper;

    /**
     * 查询我的仪器使用
     * 
     * @param equipmentLogId 我的仪器使用主键
     * @return 我的仪器使用
     */
    @Override
    public EampEquipmentMyAndEquip selectEampEquipmentMyByEquipmentLogId(Long equipmentLogId)
    {
        return eampEquipmentMyMapper.selectEampEquipmentMyByEquipmentLogId(equipmentLogId);
    }

    /**
     * 查询我的仪器使用列表
     * 
     * @param eampEquipmentMy 我的仪器使用
     * @return 我的仪器使用
     */
    @Override
    public List<EampEquipmentMyAndEquip> selectEampEquipmentMyList(EampEquipmentMyAndEquip eampEquipmentMy)
    {
        return eampEquipmentMyMapper.selectEampEquipmentMyList(eampEquipmentMy);
    }

    /**
     * 新增我的仪器使用
     * 
     * @param eampEquipmentMy 我的仪器使用
     * @return 结果
     */
    @Override
    public int insertEampEquipmentMy(EampEquipmentMy eampEquipmentMy)
    {


        return eampEquipmentMyMapper.insertEampEquipmentMy(eampEquipmentMy);
    }

    /**
     * 修改我的仪器使用
     * 
     * @param eampEquipmentMy 我的仪器使用
     * @return 结果
     */
    @Override
    public int updateEampEquipmentMy(EampEquipmentMy eampEquipmentMy)
    {
        return eampEquipmentMyMapper.updateEampEquipmentMy(eampEquipmentMy);
    }

    /**
     * 批量删除我的仪器使用
     * 
     * @param equipmentLogIds 需要删除的我的仪器使用主键
     * @return 结果
     */
    @Override
    public int deleteEampEquipmentMyByEquipmentLogIds(Long[] equipmentLogIds)
    {
        return eampEquipmentMyMapper.deleteEampEquipmentMyByEquipmentLogIds(equipmentLogIds);
    }

    /**
     * 删除我的仪器使用信息
     * 
     * @param equipmentLogId 我的仪器使用主键
     * @return 结果
     */
    @Override
    public int deleteEampEquipmentMyByEquipmentLogId(Long equipmentLogId)
    {
        return eampEquipmentMyMapper.deleteEampEquipmentMyByEquipmentLogId(equipmentLogId);
    }

    @Override
    public List<EampEquipmentMyAndEquip> selecteampEquipmentMyAndEquip(EampEquipmentMyAndEquip eampEquipmentMyAndEquip) {
        return eampEquipmentMyMapper.selecteampEquipmentMyAndEquip( eampEquipmentMyAndEquip);
    }

    @Override
    public int inable(EampEquipmentMy eampEquipmentMy) {

        int i = eampEquipmentMyMapper.updateEampEquipmentMy(eampEquipmentMy);
        //修改状态
//   EampEquipmentMyAndEquip eampEquipmentMyAndEquip = eampEquipmentMyMapper.selectEampEquipmentMyByEquipmentLogId(eampEquipmentMy.getEquipmentLogId());

//        EampEquipment eampEquipment = eampEquipmentMapper.selectEampEquipmentByEquipmentaId(eampEquipmentMyAndEquip.getEquipmentId());
        EampEquipment eampEquipment=new EampEquipment();
        eampEquipment.setEquipmentaId(eampEquipmentMy.getEquipmentId());
        eampEquipment.setUsestatus(0L);
        eampEquipmentMapper.updateEampEquipment(eampEquipment);

        String userName = SecurityUtils.getLoginUser().getUser().getUserName();
        EampEquipmentUse eampEquipmentUse=new EampEquipmentUse();
        eampEquipmentUse.setEquipmentId(eampEquipmentMy.getEquipmentId());
        eampEquipmentUse.setUsestatus(1L);
        eampEquipmentUse.setCreateBy(userName);
        eampEquipmentUse.setCreateDate(new Date());

        eampEquipmentUseMapper.insertEampEquipmentUse(eampEquipmentUse);


        return i;

    }
}
